package com.education.web.exam.api.controller;

import com.education.web.common.core.annotation.ParamsType;
import com.education.web.common.core.annotation.ParamsValidate;
import com.education.web.common.core.annotation.Param;
import com.education.web.common.core.base.BaseController;
import com.education.web.common.core.model.PageParam;
import com.education.web.common.core.utils.Result;
import com.education.web.exam.api.dto.QuestionInfoDto;
import com.education.web.exam.api.dto.QuestionInfoQuery;
import com.education.web.exam.api.service.QuestionInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 试题管理接口
 * @author zengjintao
 * @version 1.0
 * @create_at 2021/3/28 10:49
 */
@RestController
@RequestMapping("/questionInfo")
public class QuestionInfoController extends BaseController {

    @Autowired
    private QuestionInfoService questionInfoService;

    /**
     * 试题列表
     * @param pageParam
     * @param questionInfoQuery
     * @return
     */
    @GetMapping
   // @RequiresPermissions("system:question:list")
    public Result list(PageParam pageParam, QuestionInfoQuery questionInfoQuery) {
        return Result.success(questionInfoService.selectPageList(pageParam, questionInfoQuery));
    }

    /**
     * 添加或修改试题
     * @param questionInfoDto
     * @return
     */
    @PostMapping("saveOrUpdate")
    // @RequiresPermissions(value = {"system:question:save", "system:question:update"}, logical = Logical.OR)
    @ParamsValidate(params = {
            @Param(name = "schoolType", message = "请选择所属阶段"),
            @Param(name = "gradeInfoId", message = "请选择所属年级"),
            @Param(name = "subjectId", message = "请选择所属科目"),
            @Param(name = "questionType", message = "请选择试题类型"),
            @Param(name = "content", message = "请输入试题内容"),
            @Param(name = "answer", message = "请输入试题答案")
    }, paramsType = ParamsType.JSON_DATA)
    public Result saveOrUpdate(@RequestBody QuestionInfoDto questionInfoDto) {
        return Result.success(questionInfoService.saveOrUpdateQuestionInfo(questionInfoDto));
    }

    /**
     * 试题详情
     * @param id
     * @return
     */
    @GetMapping("selectById")
    public Result selectById(Integer id) {
        return Result.success(questionInfoService.selectById(id));
    }

    /**
     * 根据id 删除试题
     * @param id
     * @return
     */
    @DeleteMapping("{id}")
   // @RequiresPermissions("system:question:deleteById")
    public Result deleteById(@PathVariable Integer id) {
        return Result.success(questionInfoService.deleteById(id));
    }

}
